
cap file close summarystats

file open summarystats using "exhibits/summarystats.tex", write replace



file write summarystats "\begin{tabular}{lccccccc}" _n
file write summarystats "\hline" _n
file write summarystats "\hline" _n
file write summarystats " & (1) & (2) & (3) & (4) & (5) & (6) & (7)  \\" _n
file write summarystats "Time & Number of  & Unique & Unique & Mover's Elo  & Time  & Stockfish  & Stockfish  \\" _n
file write summarystats " Control & Observations & Players & Games & Rating & Spent &  Evaluation &  Eval. Change \\" _n
file write summarystats " &  &  & &  & (Seconds) & (Pawns) & (Pawns) \\" _n
file write summarystats "\hline" _n
file write summarystats "\\" _n

foreach xxx in 15_30 30_60 60_180 180_300 300_600 600_900 900_600{
				
	use "cleandata\winprob_matched_dataset`xxx'", clear
	
	
	drop if timecontrol_iv
	
	if "`xxx'"=="15_30" local timecontrol="15 seconds"
	if "`xxx'"=="30_60" local timecontrol="30 seconds"
	if "`xxx'"=="60_180" local timecontrol="1 minute"
	if "`xxx'"=="180_300" local timecontrol="3 minutes"
	if "`xxx'"=="300_600" local timecontrol="5 minutes"
	if "`xxx'"=="600_900" local timecontrol="10 minutes"
	if "`xxx'"=="900_600" local timecontrol="15 minutes"
	
	
	gen eval3=eval2 if substr(eval,1,1)!="#"
	
	summ timetaken
	local obs=  r(N)
	local obs:disp %10.0fc `obs'
	local obs `obs'
	local timetaken=round(r(mean),.01)
	local timetaken:disp %10.2f `timetaken'
	local timetaken `timetaken'
	local timetaken_sd=round(r(sd),.01)
	
	local timetaken_sd:disp %10.2f `timetaken_sd'
	local timetaken_sd `timetaken_sd'
	
	xtset game turn
	replace start_eval=-l.mover_eval
	
	summ start_eval
	local eval=round(r(mean)/100,.01)
	local eval:disp %10.2f `eval'
	local eval `eval'
	local eval_sd=round(r(sd)/100,.01)
	
	local eval_sd:disp %10.2f `eval_sd'
	local eval_sd `eval_sd'
	
	gen evalchange=mover_eval+l.mover_eval
	summ evalchange
	local evalchange=round(r(mean)/100,.01)
	local evalchange:disp %10.2f `evalchange'
	local evalchange `evalchange'
	
	local evalchange_sd=round(r(sd)/100,.01)
	
	local evalchange_sd:disp %10.2f `evalchange_sd'
	local evalchange_sd `evalchange_sd'
	
	summ moverelo
	local moverelo=round(r(mean),.01)
	local moverelo_sd=round(r(sd),.01)
	
	local moverelo:disp %10.0f `moverelo'
	local moverelo `moverelo'
	local moverelo_sd:disp %10.0f `moverelo_sd'
	local moverelo_sd `moverelo_sd'
	
	
	distinct game
	local numgames=  r(ndistinct)
	local numgames:disp %10.0fc `numgames'
	local numgames `numgames'
	distinct mover
	local numplayers= r(ndistinct)
	local numplayers:disp %10.0fc `numplayers'
	local numplayers `numplayers'
	
	
	
	file write summarystats "`timecontrol' & `obs' & `numplayers' & `numgames' & `moverelo' & `timetaken' & `eval' & `evalchange' \\" _n
	file write summarystats " & & & & (`moverelo_sd') & (`timetaken_sd') & (`eval_sd') & (`evalchange_sd') \\ \\" _n
	
}

file write summarystats "\hline" _n
file write summarystats "\hline" _n
file write summarystats "\end{tabular}" _n

file close summarystats


	
